package com.dajiba.demo;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.AttributeSet;

import androidx.annotation.Nullable;

import com.blankj.utilcode.util.LogUtils;

public class CustomDrawColumn extends BaseCustomView {

    public CustomDrawColumn(Context context) {
        super(context);
    }

    public CustomDrawColumn(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomDrawColumn(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        mPaint.setStyle(Paint.Style.STROKE);
        Path path = new Path();
        path.moveTo(200, 500);
        path.lineTo(200, 1200);
        path.lineTo(1000, 1200);


        canvas.drawPath(path, mPaint);


        drawPath(canvas, 300, 800, "Java");
        drawPath(canvas, 400, 500, "Python");
        drawPath(canvas, 500, 1100, "Kotlin");
        drawPath(canvas, 600, 600, "Php");
        drawPath(canvas, 700, 1190, "Go");
        drawPath(canvas, 800, 1000, "C#");
    }

    private void drawPath(Canvas canvas, int x, int height, String text) {
        Paint paint1 = new Paint();
        paint1.setColor(Color.BLACK);
        paint1.setStyle(Paint.Style.STROKE);
        paint1.setStrokeWidth(50);
        Path path1 = new Path();
        path1.moveTo(x, height);
        path1.lineTo(x, 1200);

        paint1.setTextSize(10);

        canvas.drawPath(path1, paint1);

        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(Color.BLUE);
        paint.setTextSize(25);

        Rect rect = new Rect();
        paint.getTextBounds(text, 0, text.length(), rect);
        LogUtils.d("文字宽高", rect.left, rect.top, rect.right, rect.bottom);

        int width = rect.right - rect.left;

        canvas.drawText(text, x-width/2, 1250, paint);


    }
}
